package mysql

import (
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"gorm.io/gorm"
)

type Doctor struct {
	gorm.Model
	NameCode string `gorm:"type:varchar(30);not null;comment:工号"`
	Password string `gorm:"type:varchar(32);not null;comment:密码"`
	Image    string `gorm:"type:varchar(100);comment:头像"`
}

func (d *Doctor) FindDoctorByNameCode(db *gorm.DB, code string) error {
	return db.Debug().Where("name_code=?", code).First(d).Error
}

type DoctorData struct {
	gorm.Model
	Name    string `gorm:"type:varchar(30);not null;comment:药品名称"`
	Size    string `gorm:"type:varchar(50);not null;comment:规格"`
	Person  string `gorm:"type:varchar(30);comment:生产厂商"`
	Types   string `gorm:"type:varchar(30);comment:适应症"`
	Number  int64  `gorm:"type:int(11);comment:用法用量"`
	Content string `gorm:"type:varchar(100);comment:注意事项"`
}

func (d *DoctorData) DoctorDataAdd(db *gorm.DB) error {
	return db.Debug().Create(d).Error
}
func DoctorDataList(db *gorm.DB) []*doctorrpc.DoctorDataList {
	var list []*doctorrpc.DoctorDataList
	db.Debug().Model(&DoctorData{}).
		Select(
			"name", "size", "person", "types", "number", "content",
		).
		Find(&list)
	return list
}
